<template>
  <div>
    <a-card :title="onlineDevise.chooser">
      <a-form-model ref="onlineForm" :rules="onlineFormRules" :model="onlineDevise">
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-model-item
              v-if="onlineDevise.chooser == 'Hbase+Solr'"
              label="solr collection名称"
              prop="indexName"
              :label-col="{ span: 6 }"
              :wrapper-col="{ span: 14 }"
            >
              <a-input v-model="onlineDevise.indexName" />
            </a-form-model-item>
            <a-form-model-item
              v-else
              label="ES-index名称"
              prop="indexName"
              :label-col="{ span: 6 }"
              :wrapper-col="{ span: 14 }"
            >
              <a-input v-model="onlineDevise.indexName" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="分片数量" prop="amount" :label-col="{ span: 6 }" :wrapper-col="{ span: 14 }">
              <a-input v-model="onlineDevise.amount" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      <a-table :columns="onlineColumn" :data-source="onlineData">
        <a-checkbox slot="saveFlag" slot-scope="text" :defaultChecked="text" disabled></a-checkbox>
      </a-table>
    </a-card>
  </div>
</template>

<script>
export default {
  name: 'onlineDeviseTab',
  props: {
    online: {
      type: Object
    }
  },
  data() {
    return {
      onlineDevise: this.online,
      onlineData: this.online.indexColumnList,
      onlineColumn: [
        { title: '索引字段名', dataIndex: 'columnName' },
        { title: '索引字段类型', dataIndex: 'columnType' },
        { title: '索引值是否储存', dataIndex: 'saveFlag', scopedSlots: { customRender: 'saveFlag' } },
        { title: '字段用途(必填)', dataIndex: 'columnPurpose' }
      ],
      onlineFormRules: {
        indexName: [{ required: true, message: '该正确填写值', trigger: 'blur' }],
        amount: [{ required: true, message: '分片数量不能为空', trigger: 'blur' }]
      }
    }
  },
  watch: {
    online(newVal) {
      this.onlineDevise = newVal
      this.onlineData = newVal.indexColumnList
    }
  },
  methods: {
    validateOnline() {
      let flag
      this.$refs.onlineForm.validate(valid => {
        if (valid) {
          flag = '-1'
        } else {
          flag = '2'
        }
      })
      return flag
    }
  }
}
</script>

<style scoped lang=""></style>
